package com.xl.rentkeeper.util;

import android.app.ActivityManager;
import android.content.Context;
import android.telephony.TelephonyManager;

import com.xl.rentkeeper.log.QLog;

import java.util.List;

/**
 * Created by zwc on 2015/6/30.
 */
public class AndroidUtil {
    public static final String  Tag = "AndroidUtil";
    public static String getIMEI(Context context) {
        TelephonyManager telephonyManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
        return telephonyManager.getDeviceId();
    }

    public static String getProcessName(Context context) {
        if (context == null) {
            return "unknown";
        }
        List<ActivityManager.RunningAppProcessInfo> appList = null;
        try {
            ActivityManager actMgr = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
            appList = actMgr.getRunningAppProcesses();
            for (ActivityManager.RunningAppProcessInfo info : appList) {
                if (null != info && info.pid == android.os.Process.myPid()) {
                    return info.processName;
                }
            }
        } catch (Exception e) {
            QLog.d(Tag,  "getProcessName error " + appList, e);
        }
        return "unknown";
    }
}
